package com.zuoye;


import java.util.HashMap;

import java.util.Map;
import java.util.Set;

public class Test3 {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1,"张三");
        map.put(2,"李四");
        map.put(3,"王五");
        System.out.println("集合大小"+map.size());

       //使用键找值
        Set<Integer> it = map.keySet();
        for (Integer i : it) {
            String s = map.get(i);
            System.out.println(i+s);
        }


        //使用键值对

        Set<Map.Entry<Integer, String>> en = map.entrySet();
        for (Map.Entry<Integer, String> ii : en) {
            String value = ii.getValue();
            Integer key = ii.getKey();
            System.out.println(key+value);
        }

        //获取键为1的值
        String s = map.get(1);
        System.out.println(s);

        //获取键为10的值
         String s1 = map.get(10);
        System.out.println(s1);


        //判断集合中是否有键
        System.out.println(map.containsKey(10));

        //删除键为1的键值对
        System.out.println(map.remove(1));
        System.out.println(map);


    }
}
